﻿<%
Sa.Extends("checkAction")
'公用功能类
Class commonAction
	'''上传文件页面
	Public Sub upfile()
		Sa.Dim("S_typeid")
		S_typeid = G("tid")
		Sa.Show()
	End Sub
	
	'''上传文件Post
	Public Sub upfilepost()
		Sa.Dim("S_result")
		Dim i_typeid, i_id, t_savePath, t_newFilePath, t_ftype
		Dim t_noerr : t_noerr = True
		t_savePath = "/" & C_DataFolder & "/Upload/file/" & Year(Now()) & IIF(Month(Now())<10, "0"&Month(Now()), Month(Now())) & "/"
		t_ftype = "doc/docx/xls/xlsx/ppt/htm/html/txt/zip/rar/gz/bz2"
		Sa.Use("Fso")
		Sa.Use("Upload")
		Upload.AutoSave = 2
		Upload.FileType = t_ftype
		Upload.MaxSize = 2097152
		Upload.Open()
		i_typeid = IIF(isNumeric(Upload.Form("typeid")), Clng(Upload.Form("typeid")), 0)
		i_id = Cstr((Upload.Form("id")))
		If Not Fso.IsFolder(t_savePath) Then
			t_noerr = Fso.CreateFolder(t_savePath)
			If Not t_noerr Then
				S_result = "创建文件夹时发生错误!<a href='javascript:history.go(-1)'>返回</a>"
				Exit Sub
			End If
		End If
		Upload.SavePath = t_savePath
		If Has(i_id) Then
			t_newFilePath = t_savePath & i_id & "." & Upload.Form("filename_Ext")
			Call Upload.Save("filename",i_id&"."&Upload.Form("filename_Ext"))
		Else
			Call Upload.Save("filename",0)
			t_newFilePath = t_savePath & Upload.Form("filename")
		End If
		Select Case Upload.Form("filename_Err")
		Case -1
			S_result = "没有文件上传!<a href='javascript:history.go(-1)'>返回</a>"
			Exit Sub
		Case 0
			S_result = "上传成功,请注意保存!"
			S_result = S_result & "<a href='/?g=admin&m=common&a=upfile&tid=" & i_typeid & "&id=" & i_id & "'>返回</a>" & vbcrlf
		Case 1
			S_result = "上传文件不能大于" & Fso.FormatSize(2097152, "AUTO") & "! <a href='javascript:history.go(-1)'>返回</a>"
			Exit Sub
		Case 2
			S_result = "上传文件格式错误,支持格式:" & t_ftype & "! <a href='javascript:history.go(-1)'>返回</a>"
			Exit Sub
		Case 3
			S_result = "上传文件格式错误并且文件过大! <a href='javascript:history.go(-1)'>返回</a>"
			Exit Sub
		Case Else
			S_result = "发生未知错误,代码:" & Upload.Form("filename_Err") & "! <a href='javascript:history.go(-1)'>返回</a>"
			Exit Sub
		End Select
		Select Case i_typeid
		Case 0
			S_result = "上传类型错误,代码:0!<a href='javascript:history.go(-1)'>返回</a>"
			Exit Sub
		Case 1
			S_result = S_result & "<script language='javascript'>" & vbcrlf
			S_result = S_result & "parent.document.getElementById('filepath').value='" & t_newFilePath & "';" & vbcrlf
			S_result = S_result & "</script>" & vbcrlf
		Case 2
			S_result = S_result & "<script language='javascript'>" & vbcrlf
			S_result = S_result & "parent.document.getElementById('filepath').value='" & t_newFilePath & "';" & vbcrlf
			S_result = S_result & "</script>" & vbcrlf
		Case 3
			S_result = S_result & "<script language='javascript'>" & vbcrlf
			S_result = S_result & "parent.document.getElementById('filepath').value='" & t_newFilePath & "';" & vbcrlf
			S_result = S_result & "</script>" & vbcrlf
		Case Else
			S_result = "上传类型发生错误,代码:" & i_typeid & "!<a href='javascript:history.go(-1)'>返回</a>"
			Exit Sub
		End Select
		'其实无需手动解析
		Set Upload = Nothing
	End Sub
	
	'''上传图片页面
	Public Sub uppic()
	
	End Sub
	
	'''上传图片POST
	Public Sub uppicpost()
	
	End Sub
End Class
%>